package com.godyao.mall.goods.es.repository;

import com.godyao.mall.goods.es.model.GoodsEs;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Highlight;
import org.springframework.data.elasticsearch.annotations.HighlightField;
import org.springframework.data.elasticsearch.annotations.HighlightParameters;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

import java.util.List;


/**
 * @author godyao
 * @date 2022/4/5
 */
public interface GoodsEsRepository extends ElasticsearchRepository<GoodsEs, Long> {
    @Highlight(fields = {
            @HighlightField(name = "goodsDetail"),
            @HighlightField(name = "goodsName"),
            @HighlightField(name = "goodsTitle")
    }, parameters = @HighlightParameters(
            preTags = {"<span style='color:red'>"},
            postTags = {"</span>"},
            numberOfFragments = 0,
            fragmentSize = 500
    )
    )
    List<SearchHit<GoodsEs>> findByGoodsDetailLikeOrGoodsNameLikeOrGoodsTitleLike(String goodsDetail, String goodsName, String GoodsTitle, Pageable pageable);


    int countByGoodsDetailLikeOrGoodsNameLikeOrGoodsTitleLike(String goodsDetail, String goodsName, String GoodsTitle);

    @Highlight(fields = {
            @HighlightField(name = "goodsTitle")
    }, parameters = @HighlightParameters(
            preTags = "<span style='color:red'>",
            postTags = "</span>",
            fragmentSize = 9
    )
    )
    //Page<GoodsEs> findByGoodsTitle(String goodsTitle, Pageable pageable);
    List<SearchHit<GoodsEs>> findByGoodsTitle(String goodsTitle, Pageable pageable);

    int countByGoodsTitle(String goodsTitle);

    void deleteByGoodsId(Long goodsId);
}
